package com.buddy.learn.javasource._lock;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * @author Buddy
 * @date 2021/5/15
 */
public class _CountDownLatch2 {

    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(1);
        for (int i = 0; i < 3; i++) {
            int finalI = i;
            new Thread(() -> {
                try {
                    countDownLatch.await();
                    System.out.println("线程" + finalI + "的执行时间：" + System.currentTimeMillis());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }).start();
        }
//        Thread.sleep(5000);
        TimeUnit.SECONDS.sleep(5);
        countDownLatch.countDown();
    }
}
